<?php

namespace app\common\model;

use think\Model;

class Store extends Model
{
    protected $name='store';


    /**
     * [money 变更分销商余额]
     * @Author   ZhouYunpeng
     * @DateTime 2021-01-12
     * @param    [type]      $money    [description]
     * @param    [type]      $store_id  [description]
     * @param    [type]      $type     [description]
     * @param    [type]      $memo     [description]
     * @param    integer     $order_id [description]
     * @param    integer     $status   [description]
     * @return   [type]                [description]
     */
    public static function money($money, $store_id, $type, $memo,$order_id = 0 ,$status = 2)
    {   
        $user = self::get($store_id);
        if ($user && $money != 0) {
            $before = $user->money;
            //$after = $user->money + $money;
            $after = function_exists('bcadd') ? bcadd($user->money, $money, 2) : $user->money + $money;
            //更新会员信息
            $user->save(['money' => $after]);
            //写入日志
            StoreMoneyLog::create(['store_id' => $store_id, 'order_id'=>$order_id, 'money' => $money, 'type' =>$type, 'before' => $before, 'after' => $after, 'memo' => $memo,'status'=>$status]);
            return true;
        }
    }
}